﻿using System;
using CI.Misc;
using NUnit.Framework;
using CI;
using CI.Interfaces;
using CI.Organism;

namespace Mesopotamia.UnitTests.Organism
{
    [TestFixture]
    public class RequirementTests
    {
        private IDNA _dna;
        private IOrganism _organism;
        private IChromosomeCollection _chromosomes;
        private IChromosome _chromosome;
        private IGeneCollection _genes;
        private IGene _gene;
        private HBOffsetTime _hbOffsetTime;
        private HBOffsetTimeCell _hbOffsetTimeCell;
        private IRequirementCollection _requirements;
        private ICell _cell;
        private readonly IHostingEnvironment _hostingEnvironment = new CI.Mesopotamia.MSRBHost(new MockHostingEnvironmentPhysical(), new CI.Mesopotamia.ScenarioLocalXML());
        private readonly SimEnv _simEnv = SimEnv.Instance;

        /// <summary>Test Harness setup</summary>
        [SetUp]
        public void Setup()
        {
            // reset
            _dna = new DNA();
            _hostingEnvironment.Organisms = new CI.Organism.OrganismCollection();
            _organism = new CI.Organism.Organism(_hostingEnvironment);
            _organism.Cells = new CI.Organism.CellCollection();
            _chromosome = new Chromosome(Guid.NewGuid());
            _chromosomes = new ChromosomeCollection();
            _gene = new GeneCellular(_organism, Guid.NewGuid());
            _genes = new GeneCollection();
            _requirements = new RequirementCollection();
            _cell = new Amoeba(_organism, Guid.NewGuid());
            _hbOffsetTime = new HBOffsetTime(_organism, 1, ComparisonType.Equal, Guid.NewGuid());
            _hbOffsetTimeCell = new HBOffsetTimeCell(_organism, 1, _cell, ComparisonType.Equal, Guid.NewGuid());

            // create dna structure
            _organism.DNA = _dna;
            // setup the chromosome collection
            _dna.Chromosomes = _chromosomes;
            // add a chromosome
            _chromosomes.Add(_chromosome);
            // setup the gene
            // add a gene collection
            _chromosome.Genes = _genes;
            // add a gene
            _genes.Add(_gene);
            // add a requirement colleciton to that gene
            _gene.Requirements = _requirements;
        }

        #region Heartbeat
        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void HBOffsetTimeNullOrganismArgumentException()
        {
            _hbOffsetTime = new HBOffsetTime(null, 1, ComparisonType.Equal, Guid.NewGuid());
        }

        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void HBOffsetTimeMutateNullOrganism()
        {
            _hbOffsetTime.Mutate(0, null);
        }
        #endregion

        #region Heartbeat cell
        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void HBOffsetTimeCellNullOrganismArgumentException()
        {
            _hbOffsetTimeCell = new HBOffsetTimeCell(null, 1, new Amoeba(_organism, Guid.NewGuid()), ComparisonType.Equal, Guid.NewGuid());
        }

        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Cell")]
        public void HBOffsetTimeCellNullCellArgumentException()
        {
            _hbOffsetTimeCell = new HBOffsetTimeCell(_organism, 1, null, ComparisonType.Equal, Guid.NewGuid());
        }

        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void HBOffsetTimeCellMutateNullOrganism()
        {
            _hbOffsetTimeCell.Mutate(0, null);
        }

        #endregion

        #region IOSynapseValue

        #endregion

        #region Requirment

        /// <summary>argument checker</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void RequirmentMutateNullOrganism()
        {
            _requirements.Mutate(0, null);
        }

        /// <summary>test null organism being passed to it</summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organism")]
        public void RequirmentCreateNewRequirmentException()
        {
            CI.Organism.Requirement.CreateNewRequirement(0, null);
        }

        /// <summary>test to see if it created a new gene</summary>
        [Test]
        public void RequirmentCreateNewRequirmentTrue()
        {
            Assert.IsNotNull(CI.Organism.Requirement.CreateNewRequirement(0, _organism), "New requirement not created");
        }

        #endregion

    }
}


